package com.itheima.demo;

import java.util.Scanner;

/**
 * @author jiangxun
 * @date 11-15-2024
 */
public class MovieOperator {
    private Movie[] movies;
    public MovieOperator(Movie[] movies) {
        this.movies=movies;
    }
    /**
     * 打印全部电影
     */
    public void printAllMovies() {
        System.out.println("全部电影:");
        for(int i=0;i<movies.length;i++){
            Movie movie=movies[i];
            System.out.println(movie.getId()+","+movie.getName()+","+movie.getPrice()+","+movie.getActor());
        }
    }

    /**
     * 根据电影id查询电影
     */
    public void searchMovieById() {
        System.out.println("请输入要查询的电影id：");
        Scanner scanner = new Scanner(System.in);
        int id = scanner.nextInt();
        for (int i = 0; i < movies.length; i++) {
            Movie movie = movies[i];
            if (movie.getId() == id) {
                System.out.println(movie.getId() + "," + movie.getName() + "," + movie.getPrice() + "," + movie.getActor());
            }
        }
        System.out.println("没有找到该电影");
    }
}
